<?php
namespace app\admin\controller;
use controller\BasicAdmin;
use think\Db;
use app\admin\model\withdrawModel;
class Adminwithdraw extends BasicAdmin{
    public $table = 'withdraw';

    public function user(){
        $wModel = new withdrawModel();
        list($get, $db) = [$this->request->get(), Db::name($this->table)->alias('a')->join('t_user b','a.uid=b.id','LEFT')->field('a.id,a.put_type,a.status,a.money,a.service_charge,a.real_money,b.nickname,b.username,b.mobile')];
        isset($get['type']) && $get['type'] != '' ? $db->where(['a.type'=>[$get['type']]]) : $db->where(['a.type'=>[1,2,4,3]]);
        isset($get['tel']) && $get['tel'] !='' ? $db->where(['b.mobile'=>trim($get['tel'])]) : '';
        isset($get['put_type']) && $get['put_type'] !='' ? $db->where(['a.put_type'=>$get['put_type']]) :'';
        isset($get['status']) && $get['status'] !='' ?$db->where(['a.status'=>$get['status']]) : '';
        isset($get['usertype']) && $get['usertype'] != '' ?$db->where(['a.usertype'=>$get['usertype']]) : '';
        isset($get['uid']) && $get['uid'] !='' ? $db->where(['a.uid'=>$get['uid']]) : '';

        $list = parent::_list($db,1,'','');

        //用户 1-4
        $type = $wModel->type();
        foreach($type as $k=>$v){
            if($k<=4){
                $list['type'][$k] = $v;
            }
        }
        $list['list'] = $wModel->dataname($list['list']);
        $list['put_type'] = $wModel->put_type();
        $list['status'] = $wModel->status();
        return $this->fetch('', ['title' => '用户提现列表','list'=>$list]);
    }

    /**
     * 商家
     */
    public function business(){
        $wModel = new withdrawModel();
        list($get, $db) = [$this->request->get(), Db::name('shop_capital_put')->alias('a')->join('t_shop b','a.shop_id = b.id')->field('a.id,a.put_type,a.status,b.name,b.username,b.tel')];
        isset($get['tel'])&&$get['tel'] !='' ? $db->where(['b.tel'=>trim($get['tel'])]) :'';
        isset($get['put_type']) && $get['put_type'] !='' ?$db->where(['a.put_type'=>$get['put_type']]) : '';
        isset($get['status']) && $get['status'] !='' ?$db->where(['a.status'=>$get['status']]) : '';
        $list = parent::_list($db,1,'','');
        $list['list'] = $wModel->dataname($list['list']);
        $list['put_type'] = $wModel->put_type();
        $list['status'] = $wModel->status();
        return $this->fetch('', ['title' => '商家提现列表','list'=>$list]);
    }

    /**
     * 代理商
     */
    public function agent(){
        $wModel = new withdrawModel();
        list($get, $db) = [$this->request->get(), Db::name($this->table)->alias('a')->join('user b','a.uid=b.id')];
        isset($get['type']) && $get['type'] !='' ? $db->where(['a.type'=>$get['type']]) : $db->where(['a.type'=>7]);
        isset($get['tel']) && $get['tel'] != '' ? $db->where(['b.mobile'=>trim($get['tel'])]) : '';
        isset($get['put_type']) && $get['put_type'] !='' ? $db->where(['a.put_type'=>$get['put_type']]) : '';
        isset($get['status']) && $get['status'] !='' ? $db->where(['a.status'=>$get['status']]) : '';
        isset($get['uid']) && $get['uid'] !='' ? $db->where(['a.uid'=>$get['uid']]) : '';
        isset($get['usertype']) && $get['usertype'] !='' ? $db->where(['a.usertype'=>$get['usertype']]) : '';
        $list = parent::_list($db,1,'','');
        $list['list'] = $wModel->dataname($list['list']);
        $list['put_type'] = $wModel->put_type();
        $list['status'] = $wModel->status();
        return $this->fetch('', ['title' => '代理商提现列表','list'=>$list]);
    }

    /**
     * 内部员工
     */
    public function inUser(){
        $wModel = new withdrawModel();
        list($get, $db) = [$this->request->get(), Db::name($this->table)->alias('a')->join('user b','a.uid=b.id')];
        isset($get['status']) && $get['status'] !='' ? $db->where(['a.status'=>$get['status']]) : $db->where(['a.type'=>6]);
        isset($get['tel']) && $get['tel'] !='' ? $db->where(['b.mobile'=>trim($get['tel'])]) : '';
        isset($get['put_type']) && $get['put_type'] != '' ? $db->where(['a.put_type'=>trim($get['put_type'])]) :'';
        isset($get['uid']) && $get['uid'] != '' ? $db->where(['a.uid'=>$get['uid']]) :'';
        isset($get['usertype']) && $get['usertype'] != '' ? $db->where(['a.usertype'=>$get['usertype']]) :$db->where(['a.usertype'=>5]);
        isset($get['type']) && $get['type'] != '' ? $db->where(['a.type'=>$get['type']]) :$db->where(['a.type'=>6]);
        $list = parent::_list($db,1,'','');
        $list['put_type'] = $wModel->put_type();
        $list['status'] = $wModel->status();
        $list['list'] = $wModel->dataname($list['list']);
        return $this->fetch('', ['title' => '内部员工提现列表','list'=>$list]);
    }

}